package cn.jg.framework.common.model;

import cn.jg.framework.common.model.sys.BaseUser;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.Maps;
import lombok.Data;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author fanfever
 * @date 2016/7/9
 */

@Data
@Slf4j
@SuperBuilder
@JsonIgnoreProperties(ignoreUnknown = true, value = {"sqlMap", "page"})
public abstract class BaseModel implements MixModel<Long> {
	protected Long id;
	protected BaseUser createUser;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	protected LocalDateTime createTime;
	protected BaseUser updateUser;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	protected LocalDateTime updateTime;
	protected String remark;
	protected Integer deleteFlag;

	protected transient Map<String, String> sqlMap;
	// 语言代码（查询参数）
	protected transient String languageCode;
	private transient String page;

	public BaseModel() {
		super();
		this.deleteFlag = DeleteFlag.NORMAL.getValue();
	}

	public void addSqlMap(String key, String value) {
		this.addSqlMap(key, value, 1);
	}

	public void addSqlMap(String key, String value, Integer expectedSize) {
		if (MapUtils.isEmpty(sqlMap)) {
			sqlMap = Maps.newHashMapWithExpectedSize(expectedSize);
		}
		sqlMap.put(key, value);
	}

	@Override
	@Deprecated
	public void setUpdateUserId(Integer userId) {
	}

	@Override
	@Deprecated
	public void setCreateUserId(Integer userId) {
	}

	public enum DeleteFlag {
		/**
		 *
		 */
		NORMAL(0), DELETE(1);

		private int value;

		DeleteFlag(int value) {
			this.value = value;
		}

		public int getValue() {
			return value;
		}
	}

}
